package com.briup.mt.service.impl;


import com.briup.mt.bean.BaseRole;
import com.briup.mt.bean.BaseRoleExample;
import com.briup.mt.dao.BaseRoleMapper;
import com.briup.mt.service.IBaseRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class BaseRoleServiceImpl implements IBaseRoleService {

    @Resource
    private BaseRoleMapper baseRoleMapper;

    @Override
    public List<BaseRole> query(String name) {
        BaseRoleExample example = new BaseRoleExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike( "%"+name+"%");
        }
        List<BaseRole> list = baseRoleMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(BaseRole baseRole) {
        if(baseRole.getId() == null){
            baseRoleMapper.insert(baseRole);
        } else {
            baseRoleMapper.updateByPrimaryKey(baseRole);
        }
    }

    @Override
    public void deteleById(long id) {
           baseRoleMapper.deleteByPrimaryKey(id);
    }
}
